<template>
  <!-- 左侧框 -->
  <div class="left-container">
    <!-- 标题部分 -->
    <div class="choose-header">
      <span class="title">筛选器</span>
      <div class="reset">
        <i class="el-icon-refresh-right" @click="reset"> 重置</i>
      </div>
    </div>
    <!-- 树形结构 -->
    <div class="tree-container">
      <div class="tree-box">
        <!-- 树形标题 -->
        <div class="title">
          <i />
          <span>{{ productObj.typeName }}</span>
        </div>
        <!-- 群组部分 -->
        <el-checkbox-group
          v-model="productCodes"
          class="group"
          @change="emitProSel"
        >
          <el-checkbox
            v-for="(i, l) in productObj.ruleLogProductList"
            :key="l"
            :label="i.productTypeId"
            class="node"
          >
            <div class="con">
              <span v-if="i.productTypeName.length < 10">{{ i.productTypeName }}</span>
              <el-tooltip v-else class="item" effect="dark" :content="i.productTypeName" placement="top">
                <span>{{ i.productTypeName }}</span>
              </el-tooltip>
              <span v-if="i.num < 1000">{{ i.num }}</span>
              <el-tooltip v-else class="item" effect="dark" :content="i.num" placement="top">
                <span>999+</span>
              </el-tooltip>
            </div>
          </el-checkbox>
        </el-checkbox-group>
      </div>
      <div class="tree-box">
        <!-- 树形标题 -->
        <div class="title">
          <i />
          <span>{{ failObj.typeName }}</span>
        </div>
        <!-- 群组部分 -->
        <el-checkbox-group
          v-model="failCodes"
          class="group"
          @change="emitFailSel"
        >
          <el-checkbox
            v-for="(i, l) in failObj.failReasonList"
            :key="l"
            :label="i.code"
            class="node"
          >
            <div class="con">
              <span v-if="i.name.length < 10">{{ i.name }}</span>
              <el-tooltip v-else class="item" effect="dark" :content="i.name" placement="top">
                <span>{{ i.name }}</span>
              </el-tooltip>
              <span v-if="i.num < 1000">{{ i.num }}</span>
              <el-tooltip v-else class="item" effect="dark" :content="i.num" placement="top">
                <span>999+</span>
              </el-tooltip>
            </div>
          </el-checkbox>
        </el-checkbox-group>
      </div>
    </div>
  </div>
</template>

<script>
export default {

  props: {
    productObj: {
      type: Object,
      default: () => {
        return {
          ruleLogProductList: [],
          typeName: ''
        }
      }
    },
    failObj: {
      type: Object,
      default: () => {
        return {
          failReasonList: [],
          typeName: ''
        }
      }
    }

  },
  data() {
    return {
      // 产品
      productCodes: [],
      // 失败
      failCodes: []
    }
  },
  methods: {
    // 重置
    reset() {
      this.productCodes = []
      this.failCodes = []
      this.emitFailSel()
      this.emitProSel()
    },
    // 传递产品数组
    emitProSel() {
      this.$nextTick(() => {
        this.$emit('emitProSel', this.productCodes)
      })
    },
    // 传递失败数组
    emitFailSel() {
      this.$nextTick(() => {
        this.$emit('emitFailSel', this.failCodes)
      })
    }
  }
}
</script>

  <style lang="scss" scoped>
  #app.dark-theme{
  .con,.reset,.title{
    color:#fff !important;
  }
  .el-collapse-item{
    background:rgba(59,139,255,.2) !important;
  }
}
.left-container {
  padding: 15px 0 0 3px;
  border-top: none !important;
  display: flex;
  flex-direction: column;
  // 标题样式
  .choose-header {
    width: 100%;
    height: 40px;
    padding-right: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    .title {
      font-size: 16px;
      color: #303032;
      line-height: 24px;
      font-weight: 700;
      text-align: left;
      margin: 0 0 0 10px;
    }
    // 清空内容
    .reset {
      font-size: 12px;
      color: rgba(0, 0, 0, 0.65);
      cursor: pointer;
    }
  }
  //   树形结构
  .tree-container {
    padding: 10px;
    width: 100%;
    flex: 1;
    overflow: auto;
    font-size: 14px;
    // 下面盒子
    .tree-box {
      padding: 0 0 0 0;
      //   标题部分
      .title {
        padding: 10px;
        background: #f8f8f8;
        // margin-bottom: 10px;
        i {
          margin-right: 10px;
        }
      }
      //   复选框群部分
      .group {
        padding-left: 15px;
        padding-top: 10px;
        // 单个节点
        .node {
          width: 100%;
          display: flex;
          align-items: center;
          cursor: pointer;
          padding: 10px 0;
          //   文字部分
          .con {
            width: 170px;
            display: flex;
            justify-content: space-between;
            color: #303032;

            span:nth-of-type(1) {
              flex: 3;
              overflow: hidden;
              text-overflow:ellipsis;
              white-space: nowrap;
            }
            span:nth-of-type(2) {
              flex: 1;
              text-align: right;
            }
          }
        }
      }
    }
  }
}
</style>

